Construct Non-Hierarchical P/NBD Model for Long Timeframe Synthetic Data
In this workbook we construct the non-hierarchical P/NBD models on the synthetic data with the longer timeframe.
1 Load and Construct Datasets
We start by modelling the P/NBD model using our synthetic datasets before we try to model real-life data.
Show code
use_fit_start_date <- as.Date("2010-01-01")
use_fit_end_date <- as.Date("2022-01-01")
use_valid_start_date <- as.Date("2022-01-01")
use_valid_end_date <- as.Date("2023-01-01")1.1 Load Long Time-frame Synthetic Data
We now want to load the short time-frame synthetic data.
Show code
customer_cohortdata_tbl <- read_rds("data/synthdata_longframe_cohort_tbl.rds")
customer_cohortdata_tbl |> glimpse()Rows: 50,000
Columns: 4
$ customer_id <chr> "LFC201001_0001", "LFC201001_0002", "LFC201001_0003", "…
$ cohort_qtr <chr> "2010 Q1", "2010 Q1", "2010 Q1", "2010 Q1", "2010 Q1", …
$ cohort_ym <chr> "2010 01", "2010 01", "2010 01", "2010 01", "2010 01", …
$ first_tnx_date <date> 2010-01-01, 2010-01-01, 2010-01-01, 2010-01-01, 2010-0…
Show code
customer_simparams_tbl <- read_rds("data/synthdata_longframe_simparams_tbl.rds")
customer_simparams_tbl |> glimpse()Rows: 50,000
Columns: 9
$ customer_id <chr> "LFC201001_0001", "LFC201001_0002", "LFC201001_0003", …
$ cohort_qtr <chr> "2010 Q1", "2010 Q1", "2010 Q1", "2010 Q1", "2010 Q1",…
$ cohort_ym <chr> "2010 01", "2010 01", "2010 01", "2010 01", "2010 01",…
$ first_tnx_date <date> 2010-01-01, 2010-01-01, 2010-01-01, 2010-01-01, 2010-…
$ customer_lambda <dbl> 6.349657e-02, 1.699536e-01, 4.675286e-02, 4.760263e-02…
$ customer_mu <dbl> 0.243178098, 0.122825722, 0.049332886, 0.007878287, 0.…
$ customer_tau <dbl> 6.6538597, 9.3140562, 99.3492910, 171.9080177, 0.76405…
$ customer_amtmn <dbl> 168.410136, 90.347217, 32.472693, 117.367925, 70.40242…
$ customer_amtcv <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
Show code
customer_transactions_tbl <- read_rds("data/synthdata_longframe_transactions_tbl.rds")
customer_transactions_tbl |> glimpse()Rows: 461,430
Columns: 4
$ customer_id <chr> "LFC201001_0003", "LFC201001_0002", "LFC201001_0004", "L…
$ tnx_timestamp <dttm> 2010-01-01 08:49:10, 2010-01-01 10:00:52, 2010-01-01 11…
$ invoice_id <chr> "T20100101-0001", "T20100101-0002", "T20100101-0003", "T…
$ tnx_amount <dbl> 5.80, 84.34, 6.71, 17.90, 98.92, 91.74, 122.70, 198.48, …
We re-produce the visualisation of the transaction times we used in previous workbooks.
Show code
plot_tbl <- customer_transactions_tbl |>
group_nest(customer_id, .key = "cust_data") |>
filter(map_int(cust_data, nrow) > 3) |>
slice_sample(n = 30) |>
unnest(cust_data)
ggplot(plot_tbl, aes(x = tnx_timestamp, y = customer_id)) +
geom_line() +
geom_point() +
labs(
x = "Date",
y = "Customer ID",
title = "Visualisation of Customer Transaction Times"
) +
theme(axis.text.y = element_text(size = 10))1.2 Construct Datasets
Having loaded the synthetic data we need to construct a number of datasets of derived values.
Show code
customer_summarystats_tbl <- customer_transactions_tbl |>
calculate_transaction_cbs_data(last_date = use_fit_end_date)
customer_summarystats_tbl |> glimpse()Rows: 46,119
Columns: 6
$ customer_id <chr> "LFC201001_0001", "LFC201001_0002", "LFC201001_0003", "…
$ first_tnx_date <dttm> 2010-01-01 17:28:05, 2010-01-01 10:00:52, 2010-01-01 0…
$ last_tnx_date <dttm> 2010-01-01 17:28:05, 2010-01-06 18:18:24, 2011-05-28 1…
$ x <dbl> 0, 1, 2, 11, 0, 0, 0, 30, 1, 0, 0, 2, 0, 3, 10, 1, 1, 2…
$ t_x <dbl> 0.0000000, 0.7636451, 73.1501519, 151.7046844, 0.000000…
$ T_cal <dbl> 626.0389, 626.0832, 626.0904, 626.0723, 626.0076, 626.0…
As before, we construct a number of subsets of the data for use later on with the modelling and create some data subsets.
Show code
shuffle_tbl <- customer_summarystats_tbl |>
slice_sample(prop = 1, replace = FALSE)
id_50 <- shuffle_tbl |> head(50) |> pull(customer_id) |> sort()
id_1000 <- shuffle_tbl |> head(1000) |> pull(customer_id) |> sort()
id_5000 <- shuffle_tbl |> head(5000) |> pull(customer_id) |> sort()
id_10000 <- shuffle_tbl |> head(10000) |> pull(customer_id) |> sort()We then construct some fit data based on these values.
Show code
fit_1000_data_tbl <- customer_summarystats_tbl |> filter(customer_id %in% id_1000)
fit_1000_data_tbl |> glimpse()Rows: 1,000
Columns: 6
$ customer_id <chr> "LFC201001_0016", "LFC201001_0027", "LFC201001_0094", "…
$ first_tnx_date <dttm> 2010-01-02 18:58:26, 2010-01-03 23:02:46, 2010-01-09 0…
$ last_tnx_date <dttm> 2010-01-22 00:03:58, 2010-01-03 23:02:46, 2010-06-04 1…
$ x <dbl> 1, 0, 1, 0, 9, 1, 0, 0, 0, 9, 0, 1, 45, 0, 0, 0, 0, 1, …
$ t_x <dbl> 2.7445960, 0.0000000, 20.8937253, 0.0000000, 14.7812960…
$ T_cal <dbl> 625.8871, 625.7200, 624.9566, 624.7561, 624.7663, 624.1…
Show code
fit_10000_data_tbl <- customer_summarystats_tbl |> filter(customer_id %in% id_10000)
fit_10000_data_tbl |> glimpse()Rows: 10,000
Columns: 6
$ customer_id <chr> "LFC201001_0001", "LFC201001_0004", "LFC201001_0006", "…
$ first_tnx_date <dttm> 2010-01-01 17:28:05, 2010-01-01 11:50:55, 2010-01-01 1…
$ last_tnx_date <dttm> 2010-01-01 17:28:05, 2012-11-28 10:14:09, 2010-01-01 1…
$ x <dbl> 0, 11, 0, 1, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 10, 21, 0…
$ t_x <dbl> 0.000000, 151.704684, 0.000000, 2.744596, 1.149080, 0.0…
$ T_cal <dbl> 626.0389, 626.0723, 626.0460, 625.8871, 625.8522, 625.7…
Finally, we also want to recreate our transaction visualisation for the first 50 customers randomly selected.
Show code
plot_tbl <- customer_transactions_tbl |>
filter(customer_id %in% id_50)
ggplot(plot_tbl, aes(x = tnx_timestamp, y = customer_id)) +
geom_line() +
geom_point() +
labs(
x = "Date",
y = "Customer ID",
title = "Visualisation of Customer Transaction Times"
) +
theme(axis.text.y = element_text(size = 10))1.3 Write Data
Show code
id_1000 |> write_rds("data/longframe_id_1000.rds")
id_5000 |> write_rds("data/longframe_id_5000.rds")
id_10000 |> write_rds("data/longframe_id_10000.rds")
fit_1000_data_tbl |> write_rds("data/fit_1000_longframe_data_tbl.rds")
fit_10000_data_tbl |> write_rds("data/fit_10000_longframe_data_tbl.rds")
customer_summarystats_tbl |> write_rds("data/customer_summarystats_longframe_tbl.rds")2 Fit First P/NBD Model
We now construct our Stan model and prepare to fit it with our synthetic dataset.
Before we start on that, we set a few parameters for the workbook to organise our Stan code.
Show code
stan_modeldir <- "stan_models"
stan_codedir <- "stan_code"We also want to set a number of overall parameters for this workbook
To start the fit data, we want to use the 1,000 customers. We also need to calculate the summary statistics for the validation period.
Show code
customer_fit_stats_tbl <- fit_1000_data_tbl
customer_fit_stats_tbl |> glimpse()Rows: 1,000
Columns: 6
$ customer_id <chr> "LFC201001_0016", "LFC201001_0027", "LFC201001_0094", "…
$ first_tnx_date <dttm> 2010-01-02 18:58:26, 2010-01-03 23:02:46, 2010-01-09 0…
$ last_tnx_date <dttm> 2010-01-22 00:03:58, 2010-01-03 23:02:46, 2010-06-04 1…
$ x <dbl> 1, 0, 1, 0, 9, 1, 0, 0, 0, 9, 0, 1, 45, 0, 0, 0, 0, 1, …
$ t_x <dbl> 2.7445960, 0.0000000, 20.8937253, 0.0000000, 14.7812960…
$ T_cal <dbl> 625.8871, 625.7200, 624.9566, 624.7561, 624.7663, 624.1…
Show code
customer_valid_stats_tbl <- customer_transactions_tbl |>
filter(
customer_id %in% id_1000,
tnx_timestamp > use_valid_start_date
) |>
summarise(
tnx_count = n(),
tnx_last_interval = difftime(
use_valid_end_date,
max(tnx_timestamp),
units = "weeks"
) |>
as.numeric(),
.by = customer_id
)
customer_valid_stats_tbl |> glimpse()Rows: 52
Columns: 3
$ customer_id <chr> "LFC202112_0051", "LFC201908_0155", "LFC201605_0223"…
$ tnx_count <int> 15, 11, 20, 13, 4, 5, 7, 53, 3, 20, 2, 45, 13, 18, 2…
$ tnx_last_interval <dbl> 42.3880876, 0.6080474, 3.2711051, 4.3871438, 44.4790…
2.1 Compile and Fit Stan Model
We now compile this model using CmdStanR.
Show code
pnbd_fixed_stanmodel <- cmdstan_model(
"stan_code/pnbd_fixed.stan",
include_paths = stan_codedir,
pedantic = TRUE,
dir = stan_modeldir
)We then use this compiled model with our data to produce a fit of the data.
Show code
stan_modelname <- "pnbd_long_fixed"
stanfit_prefix <- str_c("fit_", stan_modelname)
stan_data_lst <- customer_fit_stats_tbl |>
select(customer_id, x, t_x, T_cal) |>
compose_data(
lambda_mn = 0.25,
lambda_cv = 1.00,
mu_mn = 0.10,
mu_cv = 1.00,
)
pnbd_long_fixed1_stanfit <- pnbd_fixed_stanmodel$sample(
data = stan_data_lst,
chains = 4,
iter_warmup = 500,
iter_sampling = 500,
seed = 4201,
save_warmup = TRUE,
output_dir = stan_modeldir,
output_basename = stanfit_prefix,
)Running MCMC with 4 chains, at most 8 in parallel...
Chain 1 Iteration: 1 / 1000 [ 0%] (Warmup)
Chain 2 Iteration: 1 / 1000 [ 0%] (Warmup)
Chain 3 Iteration: 1 / 1000 [ 0%] (Warmup)
Chain 4 Iteration: 1 / 1000 [ 0%] (Warmup)
Chain 1 Iteration: 100 / 1000 [ 10%] (Warmup)
Chain 2 Iteration: 100 / 1000 [ 10%] (Warmup)
Chain 4 Iteration: 100 / 1000 [ 10%] (Warmup)
Chain 3 Iteration: 100 / 1000 [ 10%] (Warmup)
Chain 1 Iteration: 200 / 1000 [ 20%] (Warmup)
Chain 2 Iteration: 200 / 1000 [ 20%] (Warmup)
Chain 3 Iteration: 200 / 1000 [ 20%] (Warmup)
Chain 4 Iteration: 200 / 1000 [ 20%] (Warmup)
Chain 1 Iteration: 300 / 1000 [ 30%] (Warmup)
Chain 2 Iteration: 300 / 1000 [ 30%] (Warmup)
Chain 3 Iteration: 300 / 1000 [ 30%] (Warmup)
Chain 4 Iteration: 300 / 1000 [ 30%] (Warmup)
Chain 1 Iteration: 400 / 1000 [ 40%] (Warmup)
Chain 2 Iteration: 400 / 1000 [ 40%] (Warmup)
Chain 3 Iteration: 400 / 1000 [ 40%] (Warmup)
Chain 4 Iteration: 400 / 1000 [ 40%] (Warmup)
Chain 1 Iteration: 500 / 1000 [ 50%] (Warmup)
Chain 1 Iteration: 501 / 1000 [ 50%] (Sampling)
Chain 2 Iteration: 500 / 1000 [ 50%] (Warmup)
Chain 2 Iteration: 501 / 1000 [ 50%] (Sampling)
Chain 3 Iteration: 500 / 1000 [ 50%] (Warmup)
Chain 3 Iteration: 501 / 1000 [ 50%] (Sampling)
Chain 4 Iteration: 500 / 1000 [ 50%] (Warmup)
Chain 4 Iteration: 501 / 1000 [ 50%] (Sampling)
Chain 1 Iteration: 600 / 1000 [ 60%] (Sampling)
Chain 2 Iteration: 600 / 1000 [ 60%] (Sampling)
Chain 3 Iteration: 600 / 1000 [ 60%] (Sampling)
Chain 4 Iteration: 600 / 1000 [ 60%] (Sampling)
Chain 1 Iteration: 700 / 1000 [ 70%] (Sampling)
Chain 2 Iteration: 700 / 1000 [ 70%] (Sampling)
Chain 3 Iteration: 700 / 1000 [ 70%] (Sampling)
Chain 4 Iteration: 700 / 1000 [ 70%] (Sampling)
Chain 1 Iteration: 800 / 1000 [ 80%] (Sampling)
Chain 2 Iteration: 800 / 1000 [ 80%] (Sampling)
Chain 4 Iteration: 800 / 1000 [ 80%] (Sampling)
Chain 3 Iteration: 800 / 1000 [ 80%] (Sampling)
Chain 1 Iteration: 900 / 1000 [ 90%] (Sampling)
Chain 2 Iteration: 900 / 1000 [ 90%] (Sampling)
Chain 4 Iteration: 900 / 1000 [ 90%] (Sampling)
Chain 3 Iteration: 900 / 1000 [ 90%] (Sampling)
Chain 1 Iteration: 1000 / 1000 [100%] (Sampling)
Chain 1 finished in 15.7 seconds.
Chain 2 Iteration: 1000 / 1000 [100%] (Sampling)
Chain 2 finished in 15.8 seconds.
Chain 4 Iteration: 1000 / 1000 [100%] (Sampling)
Chain 4 finished in 16.0 seconds.
Chain 3 Iteration: 1000 / 1000 [100%] (Sampling)
Chain 3 finished in 16.2 seconds.
All 4 chains finished successfully.
Mean chain execution time: 15.9 seconds.
Total execution time: 16.4 seconds.
Show code
pnbd_long_fixed1_stanfit$summary()# A tibble: 3,001 × 10
variable mean median sd mad q5 q95 rhat ess_b…¹
<chr> <num> <num> <num> <num> <num> <num> <num> <num>
1 lp__ -2.19e+4 -2.19e+4 34.5 34.7 -2.20e+4 -2.19e+4 1.00 586.
2 lambda[1] 2.11e-1 1.67e-1 0.168 0.133 3.08e-2 5.32e-1 1.00 4631.
3 lambda[2] 1.39e-1 8.15e-2 0.164 0.0916 5.06e-3 4.78e-1 1.00 3153.
4 lambda[3] 5.97e-2 4.77e-2 0.0470 0.0378 8.66e-3 1.51e-1 1.00 4279.
5 lambda[4] 1.40e-1 8.13e-2 0.171 0.0955 4.27e-3 4.81e-1 1.00 3333.
6 lambda[5] 4.86e-1 4.69e-1 0.163 0.151 2.54e-1 7.77e-1 1.00 3856.
7 lambda[6] 3.07e-1 2.37e-1 0.253 0.196 4.11e-2 7.89e-1 0.999 3804.
8 lambda[7] 1.46e-1 8.55e-2 0.167 0.0960 5.77e-3 4.77e-1 1.00 3199.
9 lambda[8] 1.42e-1 8.53e-2 0.168 0.0953 4.87e-3 4.82e-1 1.00 2869.
10 lambda[9] 1.41e-1 8.44e-2 0.166 0.0969 4.16e-3 5.04e-1 0.999 2816.
# … with 2,991 more rows, 1 more variable: ess_tail <num>, and abbreviated
# variable name ¹ess_bulk
We have some basic HMC-based validity statistics we can check.
Show code
pnbd_long_fixed1_stanfit$cmdstan_diagnose()Processing csv files: /home/rstudio/btydwork/stan_models/fit_pnbd_long_fixed-1.csvWarning: non-fatal error reading adaptation data
, /home/rstudio/btydwork/stan_models/fit_pnbd_long_fixed-2.csvWarning: non-fatal error reading adaptation data
, /home/rstudio/btydwork/stan_models/fit_pnbd_long_fixed-3.csvWarning: non-fatal error reading adaptation data
, /home/rstudio/btydwork/stan_models/fit_pnbd_long_fixed-4.csvWarning: non-fatal error reading adaptation data
Checking sampler transitions treedepth.
Treedepth satisfactory for all transitions.
Checking sampler transitions for divergences.
No divergent transitions found.
Checking E-BFMI - sampler transitions HMC potential energy.
E-BFMI satisfactory.
Effective sample size satisfactory.
Split R-hat values satisfactory all parameters.
Processing complete, no problems detected.
2.2 Visual Diagnostics of the Sample Validity
Now that we have a sample from the posterior distribution we need to create a few different visualisations of the diagnostics.
Show code
parameter_subset <- c(
"lambda[1]", "lambda[2]", "lambda[3]", "lambda[4]",
"mu[1]", "mu[2]", "mu[3]", "mu[4]"
)
pnbd_long_fixed1_stanfit$draws(inc_warmup = FALSE) |>
mcmc_trace(pars = parameter_subset) +
expand_limits(y = 0) +
labs(
x = "Iteration",
y = "Value",
title = "Traceplot of Sample of Lambda and Mu Values"
) +
theme(axis.text.x = element_text(size = 10))We also check \(N_{eff}\) as a quick diagnostic of the fit.
Show code
pnbd_long_fixed1_stanfit |>
neff_ratio(pars = c("lambda", "mu")) |>
as.numeric() |>
mcmc_neff() +
ggtitle("Plot of Parameter Effective Sample Sizes")2.3 Assess the Model
As we intend to run the same logic to assess each of our models, we have combined all this logic into a single function run_model_assessment, to run the simulations and combine the datasets.
2.3.1 Check In-Sample Data Validation
We first check the model against the in-sample data.
Show code
assess_data_lst <- run_model_assessment(
model_stanfit = pnbd_long_fixed1_stanfit,
insample_tbl = customer_fit_stats_tbl,
outsample_tbl = customer_valid_stats_tbl,
fit_label = "pnbd_long_fixed",
fit_end_dttm = use_fit_end_date |> as.POSIXct(),
valid_start_dttm = use_valid_start_date |> as.POSIXct(),
valid_end_dttm = use_valid_end_date |> as.POSIXct(),
sim_seed = 420
)
obs_fitdata_tbl <- customer_fit_stats_tbl |>
rename(tnx_count = x)
insample_plots_lst <- create_model_assessment_plots(
obsdata_tbl = obs_fitdata_tbl,
simdata_tbl = assess_data_lst$model_fit_simstats_tbl
)
insample_plots_lst$multi_plot |> print()Show code
insample_plots_lst$total_plot |> print()Show code
insample_plots_lst$quant_plot |> print()This fit looks reasonable and appears to capture most of the aspects of the data used to fit it. Given that this is a synthetic dataset, this is not surprising, but at least we appreciate that our model is valid.
2.3.2 Check Out-of-Sample Data Validation
We now repeat for the out-of-sample data.
Show code
### We need to add all the zero count customers into the valid data
obs_validdata_tbl <- customer_fit_stats_tbl |>
anti_join(customer_valid_stats_tbl, by = "customer_id") |>
transmute(customer_id, tnx_count = 0) |>
bind_rows(customer_valid_stats_tbl) |>
arrange(customer_id)
outsample_plots_lst <- create_model_assessment_plots(
obsdata_tbl = obs_validdata_tbl,
simdata_tbl = assess_data_lst$model_valid_simstats_tbl
)
outsample_plots_lst$multi_plot |> print()Show code
outsample_plots_lst$total_plot |> print()Show code
outsample_plots_lst$quant_plot |> print()As for our short time frame data, overall our model is working well.
2.4 Write to Disk
We save this data to disk as we may want to load this data later for comparison.
Show code
assess_data_lst |> write_rds("data/pnbd_long_fixed1_assess_data_lst.rds")3 Fit Alternate Prior Model.
We want to try an alternate prior model with a smaller co-efficient of variation to see what impact it has on our procedures.
Show code
stan_modelname <- "pnbd_long_fixed2"
stanfit_prefix <- str_c("fit_", stan_modelname)
stan_data_lst <- customer_fit_stats_tbl |>
select(customer_id, x, t_x, T_cal) |>
compose_data(
lambda_mn = 0.25,
lambda_cv = 0.50,
mu_mn = 0.10,
mu_cv = 0.50,
)
pnbd_long_fixed2_stanfit <- pnbd_fixed_stanmodel$sample(
data = stan_data_lst,
chains = 4,
iter_warmup = 500,
iter_sampling = 500,
seed = 4202,
save_warmup = TRUE,
output_dir = stan_modeldir,
output_basename = stanfit_prefix,
)Running MCMC with 4 chains, at most 8 in parallel...
Chain 1 Iteration: 1 / 1000 [ 0%] (Warmup)
Chain 2 Iteration: 1 / 1000 [ 0%] (Warmup)
Chain 3 Iteration: 1 / 1000 [ 0%] (Warmup)
Chain 4 Iteration: 1 / 1000 [ 0%] (Warmup)
Chain 3 Iteration: 100 / 1000 [ 10%] (Warmup)
Chain 2 Iteration: 100 / 1000 [ 10%] (Warmup)
Chain 1 Iteration: 100 / 1000 [ 10%] (Warmup)
Chain 4 Iteration: 100 / 1000 [ 10%] (Warmup)
Chain 2 Iteration: 200 / 1000 [ 20%] (Warmup)
Chain 3 Iteration: 200 / 1000 [ 20%] (Warmup)
Chain 1 Iteration: 200 / 1000 [ 20%] (Warmup)
Chain 4 Iteration: 200 / 1000 [ 20%] (Warmup)
Chain 1 Iteration: 300 / 1000 [ 30%] (Warmup)
Chain 2 Iteration: 300 / 1000 [ 30%] (Warmup)
Chain 3 Iteration: 300 / 1000 [ 30%] (Warmup)
Chain 4 Iteration: 300 / 1000 [ 30%] (Warmup)
Chain 4 Iteration: 400 / 1000 [ 40%] (Warmup)
Chain 1 Iteration: 400 / 1000 [ 40%] (Warmup)
Chain 2 Iteration: 400 / 1000 [ 40%] (Warmup)
Chain 3 Iteration: 400 / 1000 [ 40%] (Warmup)
Chain 1 Iteration: 500 / 1000 [ 50%] (Warmup)
Chain 1 Iteration: 501 / 1000 [ 50%] (Sampling)
Chain 3 Iteration: 500 / 1000 [ 50%] (Warmup)
Chain 3 Iteration: 501 / 1000 [ 50%] (Sampling)
Chain 4 Iteration: 500 / 1000 [ 50%] (Warmup)
Chain 4 Iteration: 501 / 1000 [ 50%] (Sampling)
Chain 2 Iteration: 500 / 1000 [ 50%] (Warmup)
Chain 2 Iteration: 501 / 1000 [ 50%] (Sampling)
Chain 1 Iteration: 600 / 1000 [ 60%] (Sampling)
Chain 2 Iteration: 600 / 1000 [ 60%] (Sampling)
Chain 4 Iteration: 600 / 1000 [ 60%] (Sampling)
Chain 3 Iteration: 600 / 1000 [ 60%] (Sampling)
Chain 2 Iteration: 700 / 1000 [ 70%] (Sampling)
Chain 1 Iteration: 700 / 1000 [ 70%] (Sampling)
Chain 2 Iteration: 800 / 1000 [ 80%] (Sampling)
Chain 1 Iteration: 800 / 1000 [ 80%] (Sampling)
Chain 3 Iteration: 700 / 1000 [ 70%] (Sampling)
Chain 4 Iteration: 700 / 1000 [ 70%] (Sampling)
Chain 2 Iteration: 900 / 1000 [ 90%] (Sampling)
Chain 1 Iteration: 900 / 1000 [ 90%] (Sampling)
Chain 2 Iteration: 1000 / 1000 [100%] (Sampling)
Chain 2 finished in 8.9 seconds.
Chain 3 Iteration: 800 / 1000 [ 80%] (Sampling)
Chain 4 Iteration: 800 / 1000 [ 80%] (Sampling)
Chain 1 Iteration: 1000 / 1000 [100%] (Sampling)
Chain 1 finished in 9.2 seconds.
Chain 3 Iteration: 900 / 1000 [ 90%] (Sampling)
Chain 4 Iteration: 900 / 1000 [ 90%] (Sampling)
Chain 4 Iteration: 1000 / 1000 [100%] (Sampling)
Chain 4 finished in 11.3 seconds.
Chain 3 Iteration: 1000 / 1000 [100%] (Sampling)
Chain 3 finished in 11.3 seconds.
All 4 chains finished successfully.
Mean chain execution time: 10.2 seconds.
Total execution time: 11.5 seconds.
Show code
pnbd_long_fixed2_stanfit$summary()# A tibble: 3,001 × 10
variable mean median sd mad q5 q95 rhat ess_b…¹
<chr> <num> <num> <num> <num> <num> <num> <num> <num>
1 lp__ -39713. -3.97e+4 32.1 33.2 -3.98e+4 -3.97e+4 1.00 698.
2 lambda[1] 0.230 2.12e-1 0.105 0.0973 8.70e-2 4.39e-1 1.00 2675.
3 lambda[2] 0.213 1.90e-1 0.117 0.107 6.67e-2 4.35e-1 1.01 2528.
4 lambda[3] 0.118 1.09e-1 0.0535 0.0497 4.66e-2 2.12e-1 1.00 2792.
5 lambda[4] 0.214 1.98e-1 0.105 0.0972 7.78e-2 4.09e-1 1.00 2671.
6 lambda[5] 0.394 3.84e-1 0.110 0.110 2.34e-1 5.93e-1 1.00 2345.
7 lambda[6] 0.259 2.46e-1 0.116 0.112 9.95e-2 4.68e-1 1.00 2473.
8 lambda[7] 0.212 1.91e-1 0.114 0.104 6.78e-2 4.32e-1 1.00 2762.
9 lambda[8] 0.210 1.88e-1 0.115 0.107 6.08e-2 4.28e-1 1.00 2278.
10 lambda[9] 0.209 1.90e-1 0.110 0.104 6.81e-2 4.12e-1 1.00 2498.
# … with 2,991 more rows, 1 more variable: ess_tail <num>, and abbreviated
# variable name ¹ess_bulk
We have some basic HMC-based validity statistics we can check.
Show code
pnbd_long_fixed2_stanfit$cmdstan_diagnose()Processing csv files: /home/rstudio/btydwork/stan_models/fit_pnbd_long_fixed2-1.csvWarning: non-fatal error reading adaptation data
, /home/rstudio/btydwork/stan_models/fit_pnbd_long_fixed2-2.csvWarning: non-fatal error reading adaptation data
, /home/rstudio/btydwork/stan_models/fit_pnbd_long_fixed2-3.csvWarning: non-fatal error reading adaptation data
, /home/rstudio/btydwork/stan_models/fit_pnbd_long_fixed2-4.csvWarning: non-fatal error reading adaptation data
Checking sampler transitions treedepth.
Treedepth satisfactory for all transitions.
Checking sampler transitions for divergences.
No divergent transitions found.
Checking E-BFMI - sampler transitions HMC potential energy.
E-BFMI satisfactory.
Effective sample size satisfactory.
Split R-hat values satisfactory all parameters.
Processing complete, no problems detected.
3.1 Visual Diagnostics of the Sample Validity
Now that we have a sample from the posterior distribution we need to create a few different visualisations of the diagnostics.
Show code
parameter_subset <- c(
"lambda[1]", "lambda[2]", "lambda[3]", "lambda[4]",
"mu[1]", "mu[2]", "mu[3]", "mu[4]"
)
pnbd_long_fixed2_stanfit$draws(inc_warmup = FALSE) |>
mcmc_trace(pars = parameter_subset) +
expand_limits(y = 0) +
labs(
x = "Iteration",
y = "Value",
title = "Traceplot of Sample of Lambda and Mu Values"
) +
theme(axis.text.x = element_text(size = 10))We want to check the \(N_{eff}\) statistics also.
Show code
pnbd_long_fixed2_stanfit |>
neff_ratio(pars = c("lambda", "mu")) |>
as.numeric() |>
mcmc_neff() +
ggtitle("Plot of Parameter Effective Sample Sizes")3.2 Assess the Model
As we intend to run the same logic to assess each of our models, we have combined all this logic into a single function run_model_assessment, to run the simulations and combine the datasets.
3.2.1 Check In-Sample Data Validation
We first check the model against the in-sample data.
Show code
assess_data_lst <- run_model_assessment(
model_stanfit = pnbd_long_fixed2_stanfit,
insample_tbl = customer_fit_stats_tbl,
outsample_tbl = customer_valid_stats_tbl,
fit_label = "pnbd_long_fixed2",
fit_end_dttm = use_fit_end_date |> as.POSIXct(),
valid_start_dttm = use_valid_start_date |> as.POSIXct(),
valid_end_dttm = use_valid_end_date |> as.POSIXct(),
sim_seed = 420
)
obs_fitdata_tbl <- customer_fit_stats_tbl |>
rename(tnx_count = x)
insample_plots_lst <- create_model_assessment_plots(
obsdata_tbl = obs_fitdata_tbl,
simdata_tbl = assess_data_lst$model_fit_simstats_tbl
)
insample_plots_lst$multi_plot |> print()Show code
insample_plots_lst$total_plot |> print()Show code
insample_plots_lst$quant_plot |> print()This fit looks reasonable and appears to capture most of the aspects of the data used to fit it. Given that this is a synthetic dataset, this is not surprising, but at least we appreciate that our model is valid.
3.2.2 Check Out-of-Sample Data Validation
We now repeat for the out-of-sample data.
Show code
### We need to add all the zero count customers into the valid data
obs_validdata_tbl <- customer_fit_stats_tbl |>
anti_join(customer_valid_stats_tbl, by = "customer_id") |>
transmute(customer_id, tnx_count = 0) |>
bind_rows(customer_valid_stats_tbl) |>
arrange(customer_id)
outsample_plots_lst <- create_model_assessment_plots(
obsdata_tbl = obs_validdata_tbl,
simdata_tbl = assess_data_lst$model_valid_simstats_tbl
)
outsample_plots_lst$multi_plot |> print()Show code
outsample_plots_lst$total_plot |> print()Show code
outsample_plots_lst$quant_plot |> print()4 Fit Tight-Lifetime Model
We now want to try a model where we use priors with a tighter coefficient of variation for lifetime but keep the CoV for transaction frequency.
Show code
stan_modelname <- "pnbd_long_fixed4"
stanfit_prefix <- str_c("fit_", stan_modelname)
stan_data_lst <- customer_fit_stats_tbl |>
select(customer_id, x, t_x, T_cal) |>
compose_data(
lambda_mn = 0.25,
lambda_cv = 1.00,
mu_mn = 0.10,
mu_cv = 0.50,
)
pnbd_long_fixed4_stanfit <- pnbd_fixed_stanmodel$sample(
data = stan_data_lst,
chains = 4,
iter_warmup = 500,
iter_sampling = 500,
seed = 4202,
save_warmup = TRUE,
output_dir = stan_modeldir,
output_basename = stanfit_prefix,
)Running MCMC with 4 chains, at most 8 in parallel...
Chain 1 Iteration: 1 / 1000 [ 0%] (Warmup)
Chain 2 Iteration: 1 / 1000 [ 0%] (Warmup)
Chain 3 Iteration: 1 / 1000 [ 0%] (Warmup)
Chain 4 Iteration: 1 / 1000 [ 0%] (Warmup)
Chain 1 Iteration: 100 / 1000 [ 10%] (Warmup)
Chain 2 Iteration: 100 / 1000 [ 10%] (Warmup)
Chain 4 Iteration: 100 / 1000 [ 10%] (Warmup)
Chain 3 Iteration: 100 / 1000 [ 10%] (Warmup)
Chain 1 Iteration: 200 / 1000 [ 20%] (Warmup)
Chain 4 Iteration: 200 / 1000 [ 20%] (Warmup)
Chain 3 Iteration: 200 / 1000 [ 20%] (Warmup)
Chain 2 Iteration: 200 / 1000 [ 20%] (Warmup)
Chain 1 Iteration: 300 / 1000 [ 30%] (Warmup)
Chain 4 Iteration: 300 / 1000 [ 30%] (Warmup)
Chain 2 Iteration: 300 / 1000 [ 30%] (Warmup)
Chain 3 Iteration: 300 / 1000 [ 30%] (Warmup)
Chain 1 Iteration: 400 / 1000 [ 40%] (Warmup)
Chain 4 Iteration: 400 / 1000 [ 40%] (Warmup)
Chain 2 Iteration: 400 / 1000 [ 40%] (Warmup)
Chain 3 Iteration: 400 / 1000 [ 40%] (Warmup)
Chain 1 Iteration: 500 / 1000 [ 50%] (Warmup)
Chain 1 Iteration: 501 / 1000 [ 50%] (Sampling)
Chain 4 Iteration: 500 / 1000 [ 50%] (Warmup)
Chain 4 Iteration: 501 / 1000 [ 50%] (Sampling)
Chain 3 Iteration: 500 / 1000 [ 50%] (Warmup)
Chain 3 Iteration: 501 / 1000 [ 50%] (Sampling)
Chain 2 Iteration: 500 / 1000 [ 50%] (Warmup)
Chain 2 Iteration: 501 / 1000 [ 50%] (Sampling)
Chain 1 Iteration: 600 / 1000 [ 60%] (Sampling)
Chain 4 Iteration: 600 / 1000 [ 60%] (Sampling)
Chain 3 Iteration: 600 / 1000 [ 60%] (Sampling)
Chain 2 Iteration: 600 / 1000 [ 60%] (Sampling)
Chain 1 Iteration: 700 / 1000 [ 70%] (Sampling)
Chain 4 Iteration: 700 / 1000 [ 70%] (Sampling)
Chain 3 Iteration: 700 / 1000 [ 70%] (Sampling)
Chain 2 Iteration: 700 / 1000 [ 70%] (Sampling)
Chain 1 Iteration: 800 / 1000 [ 80%] (Sampling)
Chain 4 Iteration: 800 / 1000 [ 80%] (Sampling)
Chain 3 Iteration: 800 / 1000 [ 80%] (Sampling)
Chain 2 Iteration: 800 / 1000 [ 80%] (Sampling)
Chain 1 Iteration: 900 / 1000 [ 90%] (Sampling)
Chain 4 Iteration: 900 / 1000 [ 90%] (Sampling)
Chain 3 Iteration: 900 / 1000 [ 90%] (Sampling)
Chain 2 Iteration: 900 / 1000 [ 90%] (Sampling)
Chain 1 Iteration: 1000 / 1000 [100%] (Sampling)
Chain 1 finished in 15.1 seconds.
Chain 4 Iteration: 1000 / 1000 [100%] (Sampling)
Chain 4 finished in 15.3 seconds.
Chain 3 Iteration: 1000 / 1000 [100%] (Sampling)
Chain 3 finished in 15.4 seconds.
Chain 2 Iteration: 1000 / 1000 [100%] (Sampling)
Chain 2 finished in 15.5 seconds.
All 4 chains finished successfully.
Mean chain execution time: 15.3 seconds.
Total execution time: 15.6 seconds.
Show code
pnbd_long_fixed4_stanfit$summary()# A tibble: 3,001 × 10
variable mean median sd mad q5 q95 rhat ess_b…¹
<chr> <num> <num> <num> <num> <num> <num> <num> <num>
1 lp__ -3.22e+4 -3.22e+4 33.1 33.7 -3.22e+4 -3.21e+4 1.01 446.
2 lambda[1] 2.08e-1 1.65e-1 0.162 0.131 3.11e-2 5.29e-1 1.00 4707.
3 lambda[2] 1.44e-1 8.07e-2 0.177 0.0895 5.64e-3 5.03e-1 1.00 2429.
4 lambda[3] 6.26e-2 5.16e-2 0.0463 0.0387 1.10e-2 1.59e-1 1.00 3712.
5 lambda[4] 1.39e-1 8.10e-2 0.163 0.0915 4.96e-3 4.68e-1 1.00 2779.
6 lambda[5] 4.87e-1 4.68e-1 0.167 0.162 2.51e-1 7.90e-1 1.00 5276.
7 lambda[6] 2.96e-1 2.31e-1 0.249 0.180 3.89e-2 7.63e-1 1.00 2600.
8 lambda[7] 1.34e-1 8.25e-2 0.155 0.0915 5.43e-3 4.32e-1 1.00 2931.
9 lambda[8] 1.34e-1 8.07e-2 0.155 0.0892 5.17e-3 4.60e-1 0.999 2846.
10 lambda[9] 1.35e-1 7.78e-2 0.159 0.0888 5.42e-3 4.58e-1 1.00 2640.
# … with 2,991 more rows, 1 more variable: ess_tail <num>, and abbreviated
# variable name ¹ess_bulk
We have some basic HMC-based validity statistics we can check.
Show code
pnbd_long_fixed4_stanfit$cmdstan_diagnose()Processing csv files: /home/rstudio/btydwork/stan_models/fit_pnbd_long_fixed4-1.csvWarning: non-fatal error reading adaptation data
, /home/rstudio/btydwork/stan_models/fit_pnbd_long_fixed4-2.csvWarning: non-fatal error reading adaptation data
, /home/rstudio/btydwork/stan_models/fit_pnbd_long_fixed4-3.csvWarning: non-fatal error reading adaptation data
, /home/rstudio/btydwork/stan_models/fit_pnbd_long_fixed4-4.csvWarning: non-fatal error reading adaptation data
Checking sampler transitions treedepth.
Treedepth satisfactory for all transitions.
Checking sampler transitions for divergences.
No divergent transitions found.
Checking E-BFMI - sampler transitions HMC potential energy.
E-BFMI satisfactory.
Effective sample size satisfactory.
Split R-hat values satisfactory all parameters.
Processing complete, no problems detected.
4.1 Visual Diagnostics of the Sample Validity
Now that we have a sample from the posterior distribution we need to create a few different visualisations of the diagnostics.
Show code
parameter_subset <- c(
"lambda[1]", "lambda[2]", "lambda[3]", "lambda[4]",
"mu[1]", "mu[2]", "mu[3]", "mu[4]"
)
pnbd_long_fixed4_stanfit$draws(inc_warmup = FALSE) |>
mcmc_trace(pars = parameter_subset) +
expand_limits(y = 0) +
labs(
x = "Iteration",
y = "Value",
title = "Traceplot of Sample of Lambda and Mu Values"
) +
theme(axis.text.x = element_text(size = 10))We want to check the \(N_{eff}\) statistics also.
Show code
pnbd_long_fixed4_stanfit |>
neff_ratio(pars = c("lambda", "mu")) |>
as.numeric() |>
mcmc_neff() +
ggtitle("Plot of Parameter Effective Sample Sizes")4.2 Assess the Model
As we intend to run the same logic to assess each of our models, we have combined all this logic into a single function run_model_assessment, to run the simulations and combine the datasets.
4.2.1 Check In-Sample Data Validation
We first check the model against the in-sample data.
Show code
assess_data_lst <- run_model_assessment(
model_stanfit = pnbd_long_fixed4_stanfit,
insample_tbl = customer_fit_stats_tbl,
outsample_tbl = customer_valid_stats_tbl,
fit_label = "pnbd_long_fixed4",
fit_end_dttm = use_fit_end_date |> as.POSIXct(),
valid_start_dttm = use_valid_start_date |> as.POSIXct(),
valid_end_dttm = use_valid_end_date |> as.POSIXct(),
sim_seed = 420
)
obs_fitdata_tbl <- customer_fit_stats_tbl |>
rename(tnx_count = x)
insample_plots_lst <- create_model_assessment_plots(
obsdata_tbl = obs_fitdata_tbl,
simdata_tbl = assess_data_lst$model_fit_simstats_tbl
)
insample_plots_lst$multi_plot |> print()Show code
insample_plots_lst$total_plot |> print()Show code
insample_plots_lst$quant_plot |> print()This fit looks reasonable and appears to capture most of the aspects of the data used to fit it. Given that this is a synthetic dataset, this is not surprising, but at least we appreciate that our model is valid.
4.2.2 Check Out-of-Sample Data Validation
We now repeat for the out-of-sample data.
Show code
### We need to add all the zero count customers into the valid data
obs_validdata_tbl <- customer_fit_stats_tbl |>
anti_join(customer_valid_stats_tbl, by = "customer_id") |>
transmute(customer_id, tnx_count = 0) |>
bind_rows(customer_valid_stats_tbl) |>
arrange(customer_id)
outsample_plots_lst <- create_model_assessment_plots(
obsdata_tbl = obs_validdata_tbl,
simdata_tbl = assess_data_lst$model_valid_simstats_tbl
)
outsample_plots_lst$multi_plot |> print()Show code
outsample_plots_lst$total_plot |> print()Show code
outsample_plots_lst$quant_plot |> print()5 R Environment
Show code
options(width = 120L)
sessioninfo::session_info()─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────
setting value
version R version 4.2.2 (2022-10-31)
os Ubuntu 22.04.2 LTS
system x86_64, linux-gnu
ui X11
language (EN)
collate en_US.UTF-8
ctype en_US.UTF-8
tz Etc/UTC
date 2023-04-03
pandoc 2.19.2 @ /usr/lib/rstudio-server/bin/quarto/bin/tools/ (via rmarkdown)
─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────
package * version date (UTC) lib source
abind 1.4-5 2016-07-21 [1] RSPM (R 4.2.0)
arrayhelpers 1.1-0 2020-02-04 [1] RSPM (R 4.2.0)
backports 1.4.1 2021-12-13 [1] RSPM (R 4.2.0)
base64enc 0.1-3 2015-07-28 [1] RSPM (R 4.2.0)
bayesplot * 1.10.0 2022-11-16 [1] RSPM (R 4.2.0)
boot 1.3-28 2021-05-03 [2] CRAN (R 4.2.2)
bridgesampling 1.1-2 2021-04-16 [1] RSPM (R 4.2.0)
brms * 2.19.0 2023-04-02 [1] Github (paul-buerkner/brms@7dc5755)
Brobdingnag 1.2-9 2022-10-19 [1] RSPM (R 4.2.0)
cachem 1.0.7 2023-02-24 [1] RSPM (R 4.2.0)
callr 3.7.3 2022-11-02 [1] RSPM (R 4.2.0)
checkmate 2.1.0 2022-04-21 [1] RSPM (R 4.2.0)
cli 3.6.0 2023-01-09 [1] RSPM (R 4.2.0)
cmdstanr * 0.5.3 2023-04-02 [1] Github (stan-dev/cmdstanr@22b391e)
coda 0.19-4 2020-09-30 [1] RSPM (R 4.2.0)
codetools 0.2-18 2020-11-04 [2] CRAN (R 4.2.2)
colorspace 2.1-0 2023-01-23 [1] RSPM (R 4.2.0)
colourpicker 1.2.0 2022-10-28 [1] RSPM (R 4.2.0)
conflicted * 1.2.0 2023-02-01 [1] RSPM (R 4.2.0)
cowplot * 1.1.1 2020-12-30 [1] RSPM (R 4.2.0)
crayon 1.5.2 2022-09-29 [1] RSPM (R 4.2.0)
crosstalk 1.2.0 2021-11-04 [1] RSPM (R 4.2.0)
curl 5.0.0 2023-01-12 [1] RSPM (R 4.2.0)
digest 0.6.31 2022-12-11 [1] RSPM (R 4.2.0)
directlabels * 2021.1.13 2021-01-16 [1] RSPM (R 4.2.0)
distributional 0.3.1 2022-09-02 [1] RSPM (R 4.2.0)
dplyr * 1.1.0 2023-01-29 [1] RSPM (R 4.2.0)
DT 0.27 2023-01-17 [1] RSPM (R 4.2.0)
dygraphs 1.1.1.6 2018-07-11 [1] RSPM (R 4.2.0)
ellipsis 0.3.2 2021-04-29 [1] RSPM (R 4.2.0)
evaluate 0.20 2023-01-17 [1] RSPM (R 4.2.0)
fansi 1.0.4 2023-01-22 [1] RSPM (R 4.2.0)
farver 2.1.1 2022-07-06 [1] RSPM (R 4.2.0)
fastmap 1.1.1 2023-02-24 [1] RSPM (R 4.2.0)
forcats * 1.0.0 2023-01-29 [1] RSPM (R 4.2.0)
fs * 1.6.1 2023-02-06 [1] RSPM (R 4.2.0)
furrr * 0.3.1 2022-08-15 [1] RSPM (R 4.2.0)
future * 1.32.0 2023-03-07 [1] RSPM (R 4.2.0)
gamm4 0.2-6 2020-04-03 [1] RSPM (R 4.2.0)
generics 0.1.3 2022-07-05 [1] RSPM (R 4.2.0)
ggdist 3.2.1 2023-01-18 [1] RSPM (R 4.2.0)
ggplot2 * 3.4.1 2023-02-10 [1] RSPM (R 4.2.0)
globals 0.16.2 2022-11-21 [1] RSPM (R 4.2.0)
glue * 1.6.2 2022-02-24 [1] RSPM (R 4.2.0)
gridExtra 2.3 2017-09-09 [1] RSPM (R 4.2.0)
gtable 0.3.1 2022-09-01 [1] RSPM (R 4.2.0)
gtools 3.9.4 2022-11-27 [1] RSPM (R 4.2.0)
hms 1.1.2 2022-08-19 [1] RSPM (R 4.2.0)
htmltools 0.5.4 2022-12-07 [1] RSPM (R 4.2.0)
htmlwidgets 1.6.1 2023-01-07 [1] RSPM (R 4.2.0)
httpuv 1.6.9 2023-02-14 [1] RSPM (R 4.2.0)
igraph 1.4.1 2023-02-24 [1] RSPM (R 4.2.0)
inline 0.3.19 2021-05-31 [1] RSPM (R 4.2.0)
jsonlite 1.8.4 2022-12-06 [1] RSPM (R 4.2.0)
knitr 1.42 2023-01-25 [1] RSPM (R 4.2.0)
labeling 0.4.2 2020-10-20 [1] RSPM (R 4.2.0)
later 1.3.0 2021-08-18 [1] RSPM (R 4.2.0)
lattice 0.20-45 2021-09-22 [2] CRAN (R 4.2.2)
lifecycle 1.0.3 2022-10-07 [1] RSPM (R 4.2.0)
listenv 0.9.0 2022-12-16 [1] RSPM (R 4.2.0)
lme4 1.1-31 2022-11-01 [1] RSPM (R 4.2.0)
loo 2.5.1 2022-03-24 [1] RSPM (R 4.2.0)
lubridate * 1.9.2 2023-02-10 [1] RSPM (R 4.2.0)
magrittr * 2.0.3 2022-03-30 [1] RSPM (R 4.2.0)
markdown 1.5 2023-01-31 [1] RSPM (R 4.2.0)
MASS 7.3-58.1 2022-08-03 [2] CRAN (R 4.2.2)
Matrix 1.5-1 2022-09-13 [2] CRAN (R 4.2.2)
matrixStats 0.63.0 2022-11-18 [1] RSPM (R 4.2.0)
memoise 2.0.1 2021-11-26 [1] RSPM (R 4.2.0)
mgcv 1.8-41 2022-10-21 [2] CRAN (R 4.2.2)
mime 0.12 2021-09-28 [1] RSPM (R 4.2.0)
miniUI 0.1.1.1 2018-05-18 [1] RSPM (R 4.2.0)
minqa 1.2.5 2022-10-19 [1] RSPM (R 4.2.0)
munsell 0.5.0 2018-06-12 [1] RSPM (R 4.2.0)
mvtnorm 1.1-3 2021-10-08 [1] RSPM (R 4.2.0)
nlme 3.1-160 2022-10-10 [2] CRAN (R 4.2.2)
nloptr 2.0.3 2022-05-26 [1] RSPM (R 4.2.0)
parallelly 1.34.0 2023-01-13 [1] RSPM (R 4.2.0)
pillar 1.8.1 2022-08-19 [1] RSPM (R 4.2.0)
pkgbuild 1.4.0 2022-11-27 [1] RSPM (R 4.2.0)
pkgconfig 2.0.3 2019-09-22 [1] RSPM (R 4.2.0)
plyr 1.8.8 2022-11-11 [1] RSPM (R 4.2.0)
posterior * 1.4.0 2023-02-22 [1] RSPM (R 4.2.0)
prettyunits 1.1.1 2020-01-24 [1] RSPM (R 4.2.0)
processx 3.8.0 2022-10-26 [1] RSPM (R 4.2.0)
projpred 2.4.0 2023-02-12 [1] RSPM (R 4.2.0)
promises 1.2.0.1 2021-02-11 [1] RSPM (R 4.2.0)
ps 1.7.2 2022-10-26 [1] RSPM (R 4.2.0)
purrr * 1.0.1 2023-01-10 [1] RSPM (R 4.2.0)
quadprog 1.5-8 2019-11-20 [1] RSPM (R 4.2.0)
R6 2.5.1 2021-08-19 [1] RSPM (R 4.2.0)
Rcpp * 1.0.10 2023-01-22 [1] RSPM (R 4.2.0)
RcppParallel 5.1.7 2023-02-27 [1] RSPM (R 4.2.0)
readr * 2.1.4 2023-02-10 [1] RSPM (R 4.2.0)
reshape2 1.4.4 2020-04-09 [1] RSPM (R 4.2.0)
rlang * 1.0.6 2022-09-24 [1] RSPM (R 4.2.0)
rmarkdown 2.20 2023-01-19 [1] RSPM (R 4.2.0)
rstan 2.26.21 2023-04-02 [1] local
rstantools 2.3.0 2023-03-09 [1] RSPM (R 4.2.0)
rstudioapi 0.14 2022-08-22 [1] RSPM (R 4.2.0)
rsyslog * 1.0.2 2021-06-04 [1] RSPM (R 4.2.0)
scales * 1.2.1 2022-08-20 [1] RSPM (R 4.2.0)
sessioninfo 1.2.2 2021-12-06 [1] RSPM (R 4.2.0)
shiny 1.7.4 2022-12-15 [1] RSPM (R 4.2.0)
shinyjs 2.1.0 2021-12-23 [1] RSPM (R 4.2.0)
shinystan 2.6.0 2022-03-03 [1] RSPM (R 4.2.0)
shinythemes 1.2.0 2021-01-25 [1] RSPM (R 4.2.0)
StanHeaders 2.26.21 2023-04-02 [1] local
stringi 1.7.12 2023-01-11 [1] RSPM (R 4.2.0)
stringr * 1.5.0 2022-12-02 [1] RSPM (R 4.2.0)
svUnit 1.0.6 2021-04-19 [1] RSPM (R 4.2.0)
tensorA 0.36.2 2020-11-19 [1] RSPM (R 4.2.0)
threejs 0.3.3 2020-01-21 [1] RSPM (R 4.2.0)
tibble * 3.2.0 2023-03-08 [1] RSPM (R 4.2.0)
tidybayes * 3.0.3 2023-02-04 [1] RSPM (R 4.2.0)
tidyr * 1.3.0 2023-01-24 [1] RSPM (R 4.2.0)
tidyselect 1.2.0 2022-10-10 [1] RSPM (R 4.2.0)
tidyverse * 2.0.0 2023-02-22 [1] RSPM (R 4.2.0)
timechange 0.2.0 2023-01-11 [1] RSPM (R 4.2.0)
tzdb 0.3.0 2022-03-28 [1] RSPM (R 4.2.0)
utf8 1.2.3 2023-01-31 [1] RSPM (R 4.2.0)
V8 4.2.2 2022-11-03 [1] RSPM (R 4.2.0)
vctrs 0.5.2 2023-01-23 [1] RSPM (R 4.2.0)
withr 2.5.0 2022-03-03 [1] RSPM (R 4.2.0)
xfun 0.37 2023-01-31 [1] RSPM (R 4.2.0)
xtable 1.8-4 2019-04-21 [1] RSPM (R 4.2.0)
xts 0.13.0 2023-02-20 [1] RSPM (R 4.2.0)
yaml 2.3.7 2023-01-23 [1] RSPM (R 4.2.0)
zoo 1.8-11 2022-09-17 [1] RSPM (R 4.2.0)
[1] /usr/local/lib/R/site-library
[2] /usr/local/lib/R/library
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Show code
options(width = 80L)